package com.sky.controller.admin;

import com.sky.dto.CategoryDTO;
import com.sky.dto.CategoryPageQueryDTO;
import com.sky.entity.Category;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.CategoryService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;

/**
 * @Author by 孙有泽
 * @Date 2025/2/28 10:10
 * @Description 菜品分类controller
 */
@Api("菜品分类管理")
@RestController
@RequestMapping("/admin/category")
@Slf4j
public class CategoryController {


    @Autowired
    private CategoryService categoryService;
    /*
     * @author 孙有泽
     * @date 2025/2/28 10:19
     * @description 菜品分类新增
     */
    @ApiOperation("新增菜品分类")
    @PostMapping
    public Result saveCategory(@RequestBody CategoryDTO categoryDTO){
        log.info("新增菜品分类 {}",categoryDTO);
        categoryService.saveCategory(categoryDTO);
        return Result.success();
    }
    /*
     * @author 孙有泽
     * @date 2025/2/28 10:28
     * @description 菜品分类列表
     */
    @ApiOperation("菜品分类列表")
    @GetMapping("/page")
    public Result<PageResult> list(CategoryPageQueryDTO categoryPageQueryDTO){
        log.info("查询菜品分类列表 {}",categoryPageQueryDTO);
        PageResult pageResult=categoryService.list(categoryPageQueryDTO);
        return Result.success(pageResult);
    }
    /*
     * @author 孙有泽
     * @date 2025/2/28 10:44
     * @description 启用禁用分类
      */
    @ApiOperation("启用禁用分类")
    @PostMapping("/status/{status}")
    public Result updateStatus(@PathVariable Integer status,@RequestParam Long id) {
        log.info("启用禁用分类 status = {},ids = {}",status,id);
        categoryService.updateStatus(status,id);
        return Result.success();
    }
    /*
     * @author 孙有泽
     * @date 2025/2/28 11:21
     * @description 菜品分类删除
     */
    @ApiOperation("菜品分类删除")
    @DeleteMapping
    public Result delete(@RequestParam Long id){
        log.info("菜品分类删除 id = {}",id);
        categoryService.deleteCategory(id);
        return Result.success();
    }
    /*
     * @author 孙有泽
     * @date 2025/2/28 11:23
     * @description 菜品分类修改
     */
    @ApiOperation("菜品分类修改")
    @PutMapping()
    public Result updateCategory(@RequestBody CategoryDTO categoryDTO){
        log.info("菜品分类修改 {}",categoryDTO);
        categoryService.updateCategory(categoryDTO);
        return Result.success();
    }
    /*
     * @author 孙有泽
     * @date 2025/3/3 14:09
     * @description 菜品类型查询
     */
    @ApiOperation("菜品类型查询")
    @GetMapping("/list")
    public Result<List<Category>> list(Integer type){
        log.info("菜品类型查询");
        List<Category> list=categoryService.categoryByType(type);
        return Result.success(list);
    }


}
